package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.Buffet;
import com.ruoyi.common.utils.TimeUtils;
import com.ruoyi.system.mapper.BuffetMapper;
import com.ruoyi.system.service.BuffetService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;

/**
 * @Author: ruohao
 * @Date: 2023/9/10
 **/
@Service
public class BuffetServiceImpl implements BuffetService {
    @Resource
    private BuffetMapper buffetMapper;

    @Override
    public List<Buffet> selectList(Buffet buffet) {
        return buffetMapper.selectList(buffet);
    }

    @Override
    public Buffet getTodayMorningBuffet() {
        Buffet query = new Buffet();
//        query.setCreateTime(TimeUtils.getTodayBegin());
        query.setType("早餐");
        query.setStatus("启用");
        List<Buffet> buffets = buffetMapper.selectList(query);
        if (CollectionUtils.isEmpty(buffets)) {
            return null;
        }
        return buffets.get(0);
    }

    @Override
    public Buffet getTodayEveningBuffet() {
        Buffet query = new Buffet();
//        query.setCreateTime(TimeUtils.getTodayBegin());
        query.setType("中餐");
        query.setStatus("启用");
        List<Buffet> buffets = buffetMapper.selectList(query);
        if (CollectionUtils.isEmpty(buffets)) {
            return null;
        }
        return buffets.get(0);
    }

    @Override
    public List<Buffet> selectByIds(List<Long> ids) {
        return buffetMapper.selectByIds(ids);
    }

    @Override
    public Buffet selectById(Long id) {
        return buffetMapper.selectById(id);
    }

    @Override
    public Boolean create(Buffet buffet) {
        return buffetMapper.insert(buffet) == 1;
    }

    @Override
    public Boolean update(Buffet buffet) {
        return buffetMapper.update(buffet) == 1;
    }

    @Override
    public Boolean deleteById(Long id) {
        return buffetMapper.deleteById(id) == 1;
    }

    @Override
    public List<Buffet> selectQiyongList(String type, Long id) {
        return buffetMapper.selectQiyongList(type, id);
    }
}
